import re

def check_str(target_str):
    if len(target_str) > 8 or target_str in ("", '')  or " " in target_str:
        raise ValueError(f" \"{target_str}\" length is less than 8 and cannot contain empty characters")
    

class Bin2Dec:

    def __init__(self):
        pass

    @staticmethod
    def bin_to_dec(bin_str):
        check_str(bin_str)
        bin_pattern = "^(0|1)+$"
        new_bin = re.match(bin_pattern, bin_str)
        if new_bin is None:
            raise ValueError(f" \"{bin_str}\" contains characters other than 0 and 1.")
        number = new_bin.group()
        ans = int(number, 2)
        return str(ans)


class Dec2Bin:
    def __init__(self):
        pass

    @staticmethod
    def dec_to_bin(dec_str):
        check_str(dec_str)
        bin_pattern = "^[1-9]\d*$"
        new_bin = re.match(bin_pattern, dec_str)
        if new_bin is None:
            raise ValueError(f"\"{dec_str}\" contains non-numeric characters.")
        number = new_bin.group()
        ans = bin(int(number))
        return str(ans[2:])